package com.lvchen.ui.onefunction.banner;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;

import com.bigkoo.convenientbanner.holder.Holder;
import com.lvchen.R;
import com.lvchen.datamodel.BannerModel;
import com.makeramen.roundedimageview.RoundedImageView;
import com.nostra13.universalimageloader.core.ImageLoader;

/**
 * Created by 律晨 on 2018/6/7.
 */
public class BannerAdapter implements Holder<BannerModel> {
    RoundedImageView mImageview;

    @Override
    public View createView(Context context) {
        View view = View.inflate(context, R.layout.item_banner, null);
        mImageview = (RoundedImageView) view.findViewById(R.id.img_item);
        return view;
    }

    @Override
    public void UpdateUI(final Context context, final int position, final BannerModel url) {
        try {
            String imageUrls = url.getPhotourl();

            if (!TextUtils.isEmpty(imageUrls)) {
                ImageLoader.getInstance().displayImage(imageUrls, mImageview);
            }

            mImageview.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!TextUtils.isEmpty(url.getJumpurl())) {
                        BannerWebActivity.goToThisActivity(context, url.getTitle(), url.getJumpurl());
                    }
                }
            });

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
